import { sendMessage1 } from '../utils/aiApi';
import { ref } from 'vue';

// 修正响应式数据结构

const isLoading = ref(false); // 添加加载状态
const errorMessage = ref(''); // 添加错误信息

export const send = async (message,handleChunk,userid) => {
  try {
    // 重置状态
   
    isLoading.value = true;
    errorMessage.value = '';

    
    // 调用 API
    const fullResponse = await sendMessage1(message,'/api/deepseek/stream/chat',handleChunk,userid);

    // console.log('完整响应结果:', fullResponse);
    return fullResponse;
  } catch (error) {
    console.error('请求失败:', error);
    errorMessage.value = error.message || '请求失败';
  } finally {
    isLoading.value = false; // 无论成功或失败，都重置加载状态
  }
};

// 导出状态供组件使用
export const useChatState = () => ({

  isLoading,
  errorMessage
});